﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vds2465Telegrams;

namespace Vds2465Parser
{
	internal static class GenParse_UserData_71_DataBlockFinal
	{
		#region internal methods

		internal static byte[] GenerateBytes(UserData userData)
		{
			if (userData is UserData_71_DataBlockFinal)
			{
				UserData_71_DataBlockFinal userData71 = userData as UserData_71_DataBlockFinal;
				return GenParse_UserData_Device_Bytes.GenerateBytes(UserData.UserData71DataBlockFinal, userData71.Device, userData71.GetCopyOfBytes());
			}

			// TODO handle error - wrong UserData type
			byte[] userDataBytes = null;

			return userDataBytes;
		}

		internal static bool ParseBytes(byte[] userDataBytes, out UserData userData71DataBlockFinal, out int consumedBytes)
		{
			userData71DataBlockFinal = null;
			consumedBytes = 0;
			byte device;
			byte[] bytes;

			bool bRetVal = GenParse_UserData_Device_Bytes.ParseBytes(userDataBytes, UserData.UserData71DataBlockFinal, out device, out bytes, out consumedBytes);
			if (bRetVal)
			{
				userData71DataBlockFinal = new UserData_71_DataBlockFinal(device, bytes);
			}

			return bRetVal;
		}

		#endregion internal methods
	}
}
